package com.molin.IOtest.charstreamTest;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Demo2 {
    public static void main(String[] args) throws IOException {
//        method1();
//        method2();
//        method3();
//        method4();
        method5();
    }

    public static void method5() throws IOException {
        String path="D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\charstreamTest\\a.txt";
        FileWriter fw=new FileWriter(new File(path));
        String line="沫林是个程序员abcdef";

        fw.write(line,0,2);
        fw.close();
    }

    public static void method4() throws IOException {
        String path="D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\charstreamTest\\a.txt";
        FileWriter fw=new FileWriter(new File(path));
        String line="沫林是个程序员abcdef";
        fw.write(line);
        fw.close();
    }

    public static void method3() throws IOException {
        String path="D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\charstreamTest\\a.txt";
        FileWriter fw=new FileWriter(new File(path));
        char [] chars={97,98,99,100,101,102};
        fw.write(chars,0,3);
        fw.close();
    }

    public static void method2() throws IOException {
        String path="D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\charstreamTest\\a.txt";
        FileWriter fw=new FileWriter(new File(path));
        char [] chars={97,98,99,100,101};
        fw.write(chars);
        fw.close();
    }

    public static void method1() throws IOException {
        String path="D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\charstreamTest\\a.txt";
        FileWriter fw=new FileWriter(new File(path));

        //写数据
        fw.write(97);
        fw.write(98);
        fw.write(99);

        fw.close();
    }
}
